package acwing.图;

import java.util.Scanner;

/**
 * Floyd求最短路
 *
 * @author yang
 * @date 2022/1/13
 */
public class Floyd求最短路 {

    static int N = 210;

    static int[][] p = new int[N][N];
    static int n, m, q;
    static int INF = 0x3f3f3f3f;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        m = sc.nextInt();
        q = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (i == j) p[i][j] = 0;
                else p[i][j] = INF;
            }
        }
        while (m-- > 0) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int w = sc.nextInt();
            p[a][b] = Math.min(p[a][b], w);
        }
        floyd();
        while (q-- > 0) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            if (p[a][b] > INF / 2) System.out.println("impossible");
            else System.out.println(p[a][b]);
        }
    }

    private static void floyd() {

        for (int k = 1; k <= n; k++) {
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    p[i][j] = Math.min(p[i][j], p[i][k] + p[k][j]);
                }
            }
        }
    }
}
